const http = uni.$u.http
/**
 * 文件上传
 */
// 修改密码（根据sysUserId）
export const updatePasswordApi = (data) => http.put('/sys/user/changePasswordBySysUserId', data)
/**
 * 文件上传（改用小程序原生uni.uploadFile，彻底解决参数类型错误）
 * @param {string} filePath - 小程序临时文件路径
 * @returns {Promise} 上传结果
 */
export const OssUpload = (filePath) => {
	return new Promise((resolve, reject) => {
		const token = uni.getStorageSync('token').tokenValue;
		console.log(token)
		uni.uploadFile({
			url: uni.$u.http.config.baseURL + 'oss/upload',
			filePath: filePath,
			name: 'file',
			header: {
				'SA-TOKEN-USER': token,
				'Content-Type': 'multipart/form-data; boundary=XXX'
			},
			success: (res) => {
				let result;
				try {
					result = JSON.parse(res.data);
				} catch (e) {
					result = {
						code: res.statusCode,
						msg: res.data
					};
				}
				resolve(result);
			},
			fail: (err) => {
				reject(err);
			}
		});
	});
}

/**
 * 微信登录
 */
export const wxLoginApi = (code) => http.get('/Vip/login?code=' + code)
/**
 * 退出登录
 */
export const wxlogoutApi = (code) => http.post('/Vip/logout')

// export const updateUserInfoApi = (data) => http.post('/Vip/updateUserInfo', data)
// 新增更新用户信息接口（POST方式）
export const updateUserInfoApi = (data) => http.post('/Vip/updateInfo', data);
/**
 * 自定义添加公司
 */
export const addcustomCompany = (data) => http.post(`/Vip/addcustomCompany`, data)
/**
 * 获取用户信息
 * */
export const getUserInfoApi = () => http.get('/Vip/getInfo')
/**
 * 绑定码绑定公司
 * */
export const bindingApi = (bindingCode) => http.post(`/Vip/binding/${bindingCode}`)
/**
 * 查询公司
 * */
export const getCompanyApi = (companyName) => http.get('/Vip/getCompanyList?companyName=' + companyName)
/**
 *  解绑公司
 * */
export const deleteCompanyApi = (companyId) => http.delete(`/Vip/unBinding/${companyId}`)
/**
 *  获取税费种列表
 * */
export const typeListApi = (params) => http.get('/Vip/feeType/list', {
	params
})
/**
 * 根据公司Id查询申报情况
 */
export const getDeclarationApi = (params) => http.get('/CustomerDeclaration/getByCustomerIdYearMonth', {
	params
})
export const batchBindingApi = (data) => http.post('/Vip/batchBinding', data)

export const getContractApi = (companyId) => http.get(`/CustomerContract/byCompanyId/${companyId}`)
export const getContractCurrentApi = (companyId) => http.get(`/CustomerContract/current/${companyId}`)

export const generatorContractApi = (data) => http.post('/CustomerContract/generatorContract', data)

export const currentCompanyApi = () => http.get('/Vip/currentCompany')

export const firstBindingApi = (bindingCode) => http.post(`/Vip/onceBinding/${bindingCode}`)

export const changeCurrentCompanyApi = (companyId) => http.put(`/Vip/changeCurrentCompany/${companyId}`)

export const checkRealNameApi = (data) => http.post('/CustomerContract/checkRealNameAuthentication', data)

export const sendLegalBindingMsgApi = (phone) => http.get(`/Vip/sendLegalBindingMsg/${phone}`)

export const batchBindingSaveApi = (companyIds, isFirst) => http.post(
	`/Vip/batchBindingSave/${companyIds}?isFirst=${isFirst}`)

export const currentApi = (companyId) => http.get(`/CustomerContract/current/${companyId}`)